package com.cqw.classtest;

import com.cqw.classtest.obj.User;

import java.util.*;

/**
 * @Author: caoqingwen
 * @CreateTime: 2022-03-16 20:00
 * @Description:
 */
public class ArraylistClass {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        List<Object> list1 = null;


        list.add("abc");
        list.add("def");
        list.add(1, "ghi");

        list.sort(Comparator.comparing(String::new));


        List<User> userList = new ArrayList<>();
        userList.add(new User(1L, "张三", 10));
        userList.add(new User(4L, "赵六", 40));
        userList.add(new User(3L, "王五", 30));
        userList.add(new User(2L, "李四", 20));
        userList.sort(Comparator.comparing(User::getId).reversed());

        userList.forEach(user -> {
            if (user.getId() == 1L) {
                user.setAge(60);
                return;
            }
            user.setAge(50);
        });

        userList.removeIf(user -> user.getId() == 1L);

        //userList.clear();

        Iterator<User> iterator = userList.iterator();
        while (iterator.hasNext()) {
            User next = iterator.next();
            System.out.println(next);
        }


        ListIterator<User> userListIterator = userList.listIterator();


        //userList.forEach(System.out::println);


    }


}
